﻿using System.Drawing;
using Core.Controllers;
using Core.Debug;
using Core.View.Builders;
using Core.View.Renders;

namespace Core.Model
{
    public class World
    {
        #region Constants

        public static readonly int SEED = 123;

        public static readonly Color NIGHTCOLOR = Color.Black;
        public static readonly Color SUNCOLOR = Color.White;
        public static readonly Color HORIZONCOLOR = Color.White;

        public static readonly Color EVENINGTINT = Color.Red;
        public static readonly Color MORNINGTINT = Color.Gold;

        #endregion

        public World(WorldRenderer render, ChunkBuilder builder, SkyDomeRenderer skyDomeRenderer, WorldDebugger debugger)
        {
            Debugger = debugger;

            SkyDomeRenderer = skyDomeRenderer;

            Render = render;

            Player = new Player();

            Camera = new Camera();

            Camera.InitializeCamera(this);

            ChunkManager = new ChunkManager();

            ChunkManager.Initialize(this, builder);
        }

        #region Properties

        public WorldDebugger Debugger;

        public SkyDomeRenderer SkyDomeRenderer;
        
        public WorldRenderer Render;

        public Player Player;

        public Camera Camera;

        private ChunkManager ChunkManager;

        #endregion

        #region Public methods

        public void Draw()
        {
            Render.BeginDraw();

            Render.DrawTerrain(Camera, ChunkManager.Values);

            if (SkyDomeRenderer != null)
            {
                SkyDomeRenderer.Draw(Camera);
            }

            Render.EndDraw();
        }

        public void Update()
        {
            Camera.Update();

            Player.Update();

            if (SkyDomeRenderer != null)
            {
                SkyDomeRenderer.Update();
            }
        }

        #endregion
    }
}
